<?php
	require "../banco/ConexaoBanco.php";
	
	function convertDataEmDMA($dt)
	{
		$dia = substr($dt,8,2);
		$mes = substr($dt,5,2);
		$ano = substr($dt,0,4);
		$data = $dia."/".$mes."/".$ano;
		return $data;
	}
	$id = isset($_GET['id']) ? (int)$_GET['id'] : false;
	 
	//Query simples para busca dos dados
	$sql = mysql_query("SELECT * FROM receita WHERE id_receita = '$id'")or die(mysql_error());
	//VerificaÃ§Ã£o das linhas encontradas.
	$verSql = mysql_fetch_array($sql);
	
	$busca = mysql_query("SELECT p_nome, m_nome, m_crm, m_especialidade FROM medico, paciente WHERE id_paciente = ".$verSql['paciente_id']." AND id_medico = ".$verSql['medico_id'] );
	
	$ver = mysql_fetch_array($busca);

	//formatando o pdf
	require("../fpdf/fpdf.php");
	
	$pdf= new FPDF("P","pt","A4");
	
	$pdf->AddPage();
	
	$pdf->Ln(30);
	$pdf->SetFont('Times','B',16);
	$pdf->Cell(0,30,utf8_decode("RECEITA MÉDICA"),0,1,'C');
	$pdf->Cell(0,5,"","B",1,'C');
	$pdf->Ln(50);
	
	$pdf->SetFont('Times','B',12);
	$pdf->Cell(70,20,"Data:",0,0,'L');
	$pdf->setFont('Times','',12);
	$pdf->Cell(0,20,convertDataEmDMA($verSql['r_data']),0,1,'L');
	$pdf->Ln(8);
	
	$pdf->SetFont('Times','B',12);
	$pdf->Cell(70,20,"Paciente:",0,0,'L');
	$pdf->setFont('Times','',12);
	$pdf->Cell(0,20,utf8_decode($ver['p_nome']),0,1,'L');
	$pdf->Ln(8);
	
	$pdf->SetFont('Times','B',12);
	$pdf->Cell(70,20,utf8_decode("Prescrição Médica:"),0,0,'L');
	$pdf->Cell(0,20,"",0,1,'L');
	$pdf->setFont('Times','',12);
	$pdf->MultiCell(0,20,utf8_decode($verSql['r_descricao']),0,'J');
	$pdf->Ln(200);
	
	$pdf->Cell(0,5,"_______________________________",0,1,'C');
	$pdf->setFont('Times','',12);
	$pdf->Cell(0,30,utf8_decode($ver['m_nome'] ." - ". $ver['m_especialidade']),0,1,'C');
	$pdf->setFont('Times','',12);
	$pdf->Cell(0,5,utf8_decode("CRM: ".$ver['m_crm']),0,1,'C');
	
	$pdf->Output();
	
?>
